package com.zh.juc.interrupt;

import java.util.concurrent.TimeUnit;

/**
 * @Author: zhanghuan
 * @date: 2022/10/10 20:03
 * @description: create it
 */
public class InterruptDemo2 {
    public static void main(String[] args) {
        // interrupt 仅仅是设置线程的中断状态为true,发起协商不会立即停止线程
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 300; i++) {
                System.out.println("-----: " + i);
            }
            System.out.println("t1线程调用interrupt()后的中断标识02：" + Thread.currentThread().isInterrupted());
        }, "t1");
        t1.start();

        System.out.println("t1线程默认中断标志：" + t1.isInterrupted()); //false
        try {
            TimeUnit.MILLISECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t1.interrupt();//true

        System.out.println("t1线程调用interrupt()后的中断标识01：" + t1.isInterrupted());//true
        try {
            TimeUnit.MILLISECONDS.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("t1线程调用interrupt()后的中断标识03：" + t1.isInterrupted());//false
    }
}
